
package action;

import db.User;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 * Show all users.
 * @author Tomas CASTA
 */
@UrlBinding("/users.action")
public class ShowUsersActionBean implements ActionBean {
    /* action context */
    private ActionBeanContext context;
    private User user;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getUser() {
        return user;
    }

    /**
     * Show all users.
     * @return Resolution
     */
    @DefaultHandler
    public Resolution show() {
        /* User is logged */
        if (null != context.getRequest().getSession().getAttribute("user")) {
            user = new User();
            user.setDb(this.context.getServletContext());
            user.showAllUsers();
            return new ForwardResolution("/jsp/showUsers.jsp");
        }
        /* User is not logged, show index */
        else {
            return new ForwardResolution("index.action");
        }

    }
}
